/**
 * @param nums
 * @param target
 * @return {number[]}
 */
// let nums = [2, 7, 11, 15], target = 9;
let nums = [3, 2, 1, 7,3], target = 6;

// 时间复杂度约等于O(n)
let twoNum = function (nums, target) {
    let i = 0;
    let temp = {};
    while (i < nums.length) {
        let num = target - nums[i];
        if (temp[num] !== undefined) {
            return [temp[num], i];
        }
        temp[nums[i]] = i;
        i++;
    }
};

console.log(twoNum(nums, target));
